package ooo.reindeer.concurrent.netqueue.handler;

import io.netty.channel.*;
import ooo.reindeer.logging.ILogger;
import ooo.reindeer.logging.LogUtil;

public class ExceptionHandler extends ChannelDuplexHandler {

    private static final ILogger logger = LogUtil.getLogger(ExceptionHandler.class);

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ctx.write(msg, promise.addListener(new ChannelFutureListener() {
            @Override
            public void operationComplete(ChannelFuture future) throws Exception {
                if (!future.isSuccess()) {
                    logger.error("send data to client exception occur: ", future.cause());
                }
            }
        }));
    }
}
